//
//  objc_msgSend底层实现.h
//  面试题
//
//  Created by Toj on 8/15/21.
//

#pragma mark - 3. 底层实现
{
    ENTRY _objc_msgSend
    UNWIND _objc_msgSend, NoFrame

    // #0是传入的第一个参数
    cmp    p0, #0            // nil check and tagged pointer check
    // 判断是不是标记指针
#if SUPPORT_TAGGED_POINTERS
    // 跳转 LNilOrTagged
    b.le    LNilOrTagged        //  (MSB tagged pointer looks negative)
#else
    // 跳转 LReturnZero
    b.eq    LReturnZero
#endif
    ldr    p13, [x0]        // p13 = isa
    GetClassFromIsa_p16 p13, 1, x0    // p16 = class
LGetIsaDone:
    // calls imp or objc_msgSend_uncached
    // 遍历缓存取IMP
    CacheLookup NORMAL, _objc_msgSend, __objc_msgSend_uncached

#if SUPPORT_TAGGED_POINTERS
LNilOrTagged:
    b.eq    LReturnZero        // nil check
    GetTaggedClass
    b    LGetIsaDone
// SUPPORT_TAGGED_POINTERS
#endif

LReturnZero:
    // x0 is already zero
    mov    x1, #0
    movi    d0, #0
    movi    d1, #0
    movi    d2, #0
    movi    d3, #0
    ret

    END_ENTRY _objc_msgSend
}
